package Config::System::MooseX::Getopt;

use Moose::Role;
use Config::System; # need access to Store

with 'MooseX::Getopt';

has set => (is => 'ro', isa => 'HashRef', default => sub { {} });

# TODO make this role parameterized, so users can choose the name of the args hash, by default "set"

# set every pair found in the attribute "set" into the store
around new_with_options => sub {
    my ($next, @args) = @_;
    my $self = $next->(@args);
    my %properties = %{ $self->set };
    my $store = Store;
    for my $name (keys %properties) {
        my $value = $properties{$name};
        $name =~ s/::([^:]+)$//;
        my $property = $1;
        $store->set($name, $property, $value);
    }
    return $self;
};

1;
